import requests
import time  # Add time module

# Configuration
CONNECT_SID = 'FzPdrPFj0WuzKeCnCVOOfW65.tpLzeEVcFxBpa4ov%2FrPFj0Wu'
TOPIC_IDS = [
    '42249189a470164c0f1faa7b490b857c',
    '214946d2342dba39409d6cf70e9d29a8',
    # Add more topic IDs here as needed
]

def export_topic(topic_id: str, cookie_sid: str) -> bool:
    url = f'https://rizzoma.com/api/export/1/{topic_id}/html/'
    headers = {
        'Cookie': f'connect.sid={cookie_sid}'
    }
    
    response = requests.get(url, headers=headers)
    
    if response.status_code == 200:
        with open(f'{topic_id}.html', 'wb') as file:
            file.write(response.content)
        print(f'Topic {topic_id} downloaded successfully.')
        return True
    else:
        print(f'Failed to download topic {topic_id}. Status code: {response.status_code}')
        return False

# Example usage
if __name__ == '__main__':
    for topic_id in TOPIC_IDS:
        export_topic(topic_id, CONNECT_SID)
        time.sleep(0.3)  # Add small delay to prevent rate limiting
